package com.example.smartcity_ikun3.ui.home.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.smartcity_ikun3.R
import com.example.smartcity_ikun3.logic.util.Util.show
import com.example.smartcity_ikun3.ui.App
import com.example.smartcity_ikun3.ui.App.Companion.url
import com.example.smartcity_ikun3.ui.home.HomeViewModel
import com.example.smartcity_ikun3.ui.home.adapter.ReAdapterNews
import com.example.smartcity_ikun3.ui.home.fragment.NewsShowFragment
import com.example.smartcity_ikun3.ui.home.fragment.NewsShowFragment.Companion.idNum
import com.example.smartcity_ikun3.ui.home.model.NewsEntity
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.android.synthetic.main.activity_news.*
import kotlinx.android.synthetic.main.fragment_news_show.*

/**
 * 更多生活咨询
 */
class NewsActivity : AppCompatActivity() {

    private val viewModel by lazy {
        ViewModelProviders.of(this).get(HomeViewModel::class.java)
    }

    private lateinit var mNewsRecyclerView: RecyclerView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        setContentView(R.layout.activity_news)

        NewsViewPager2.adapter = object : FragmentStateAdapter(this){
            override fun getItemCount(): Int = 5

            override fun createFragment(position: Int): Fragment = when(position){
                0 -> NewsShowFragment()
                1 -> NewsShowFragment()
                2 -> NewsShowFragment()
                3 -> NewsShowFragment()
                4 -> NewsShowFragment()
                else -> NewsShowFragment()
            }

            override fun getItemId(position: Int): Long {
                idNum = when(position){
                    0 -> 26
                    1 -> 27
                    2 -> 28
                    3 -> 29
                    else -> 30
                }
                return super.getItemId(position)
            }
        }



        TabLayoutMediator(NewsTabLayout, NewsViewPager2){tab, position ->
            when(position){
                0 -> tab.text = "新闻"
                1 -> tab.text = "时尚"
                2 -> tab.text = "教育"
                3 -> tab.text = "房产"
                else -> tab.text = "汽车"
            }
        }.attach()
    }

    private fun setNews() {

    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}